import Router from "koa-router";
import httpRequest from "@/utils/http";
import { Result } from "@/utils/result";

const bgImgRouter = new Router({ prefix: "/api/daily/bgimg" });
const platformInfo = {
    unsplash: {
        name: "unsplash",
        url: "https://api.codelife.cc/wallpaper/unsplash?lang=cn&per_page=12&page=1&type=experimental",
        lang: "cn",
        per_page: "12",
        page: 1,
        // 类别
        type: "experimental", //热门, 近期更新：editorial；壁纸：wallpapers；创意：3d-renders；纹理图案：textures-patterns；摄影：film，风景：nature
        interface: {
            code: 200,
            data: [
                {
                    id: "CzQWRxFjXZE",
                    w: 6000,
                    h: 4000,
                    raw: "https://dogefs.s3.ladydaily.com/~/source/unsplash/photo-1680504726680-eac69a70e16b?ixid=M3wyNjY4NDZ8MHwxfHRvcGljfHxxUFlzRHp2Sk9ZY3x8fHx8Mnx8MTY4NTE1NTAyOXw&ixlib=rb-4.0.3&w=2560&h=1440&fmt=webp",
                    thumb: "https://dogefs.s3.ladydaily.com/~/source/unsplash/photo-1680504726680-eac69a70e16b?ixid=M3wyNjY4NDZ8MHwxfHRvcGljfHxxUFlzRHp2Sk9ZY3x8fHx8Mnx8MTY4NTE1NTAyOXw&ixlib=rb-4.0.3&w=300&h=150&fmt=webp"
                }
            ],
            msg: "加载成功"
        }
    },
    wallhaven: {
        name: "wallhaven",
        url: "https://api.codelife.cc/wallpaper/wallhaven?lang=cn&page=1&sorting=random&topRange=6M&q=id:2321",
        lang: "cn",
        page: 1,
        sorting: "random",
        topRange: "6M",
        // 类别
        q: "id:2321", // 为空为热门，吉卜力：id:1748，像素：id:376，数字艺术：id:13，风景：id:711
        interface: {
            code: 200,
            data: [
                {
                    raw: "https://dogefs.s3.ladydaily.com/~/source/wallhaven/full/dg/wallhaven-dgxm1l.jpg?w=2560&h=1440&fmt=webp",
                    thumb: "https://dogefs.s3.ladydaily.com/~/source/wallhaven/small/dg/dgxm1l.jpg?w=400&h=200&fmt=webp",
                    id: "dgxm1l"
                }
            ],
            msg: "请求成功"
        }
        // 动态壁纸，其实就是个小视频
    },
    video: {
        name: "video",
        url: "https://api.codelife.cc/wallpaper/video/list?lang=cn&page=1&size=16&sortKey=updateTime",
        lang: "cn",
        page: 1,
        size: 16,
        sortKey: "updateTime",
        interface: {
            code: 200,
            data: [
                {
                    _id: "625526fe452009fb7a5feb9a",
                    url: "https://files.codelife.cc/itab/defaultWallpaper/videos/33.mp4",
                    thumb: "https://files.codelife.cc/itab/defaultWallpaper/videos/33.jpg",
                    poster: "https://files.codelife.cc/itab/defaultWallpaper/videos/33.mp4?x-oss-process=video/snapshot,t_1,f_jpg,w_1366,h_768,m_fast"
                }
            ],
            msg: "请求成功",
            count: 100,
            page: 1,
            size: 16,
            pages: 7
        }
    }
};

bgImgRouter.get("/", async (ctx, next) => {
    const unsplashTypes = [
        "experimental",
        "editorial",
        "wallpapers",
        "3d-renders",
        "textures-patterns",
        "film",
        "nature"
    ];
    const type = unsplashTypes[Math.floor(Math.random() * unsplashTypes.length)];
    // 获取 unsplash 随机分类壁纸
    // const { data: result } = await axios.get(
    //     `https://api.codelife.cc/wallpaper/unsplash?lang=cn&per_page=12&page=1&type=${type}`
    // );
    const res = await httpRequest.get({
        baseURL: `https://api.codelife.cc/wallpaper/unsplash?lang=cn&per_page=12&page=1&type=${type}`
    });
    Result.ok(ctx, res.data);

    // ctx.body = {
    //     code: 200,
    //     data: result.data,
    //     msg: "图片请求成功"
    // };
});

export default bgImgRouter;
